﻿#ifndef SCREEN_H
#define SCREEN_H
#include <QWidget>
#include <QSharedPointer>
#include "myrect.h"
#include"qslabel.h"
#include"controlwidget.h"
#include "pensetting.h"
#include "amplifier.h"

//控制面板

#define WIDTHINFO_HEIGHTMARGIN 1
enum Type {
    RECT1, RECT2, RECT3, RECT4, RECT5, NO
};


class QSLabel;
class ControlWidget;

class Screen : public QWidget
{
    Q_OBJECT
public:
    explicit Screen(QWidget *parent = nullptr);
    ~Screen() override;

    void Init();
    void Exit(int code);

    void clearImagelable();

    //绘制高亮窗口
    bool comparePoint(QPoint &p1, QPoint &p2);

    void moveControls();

    //返回截取之后的图片
    QPixmap getGrabPixmap();

    //保存截图
    void savePixmap();
    void grabImage();
    void doForward();
    void complete();
    void updateSelectedWindow(void);
    bool getSmallestWindowFromCursor(QRect &windowRect);
    void updateControlPos(int topLeftx,int topLeftY,int bottomRightY, int bottomRightX);

    QPainterPath getPath();

    PenSetting *getPensetting() const;

    void setUndoEnable(bool undoEnable);

    Q_INVOKABLE void cancel();

    bool close();

protected:
    void paintEvent(QPaintEvent *) override;
    void mousePressEvent(QMouseEvent *) override;
    void mouseReleaseEvent(QMouseEvent *) override;
    void mouseMoveEvent(QMouseEvent *) override;
    //void mouseDoubleClickEvent(QMouseEvent* event) override;
    void keyPressEvent(QKeyEvent *e) override;

signals:
    void finished(int code);
    void forward(QPixmap img);

private:
    QPixmap pixmap;               //全屏
    QPoint pressedPoint;          //鼠标左键按下后的坐标
    QPoint movePoint;             //终点坐标
    QPainterPath globalPath;      //保存全局路径

    bool         oncePress;       //是不是第一次左键按下
    bool         isLeftPressed;   //左键是否已经按下

    QSharedPointer<MyRect>       widthInfoRect;//截取区域的长宽信息矩形
    QSharedPointer<Amplifier>    amplifierRect;//当前鼠标位置像素

    QPoint       oldPoint;        //原先的坐标 capturerbeginpoint
    QWidget     *control = nullptr;
    ControlWidget *controlUi = nullptr;
    PenSetting *pensetting = nullptr;
    //QRect rec;
    QSLabel *labelimage = nullptr;
    /// 当前鼠标移动时高亮的窗口
    QRect m_highlightwindow;
    int ratio = 1;
};

#endif // SCREEN_H
